<?php
include("./config.php");
include("./utils.php");
?>
<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <title>快捷键壁纸</title>
  <?php include 'scripts-inc.php' ?>
  
  <script>

function column_template(){/*
<section class="clearfix wrap-cate col-md-12">

<div class="row">
  <img class="col-xs-3 col-sm-1 col-md-1 col-lg-1" style='margin-top:24px; max-width:96px;_width:expression(this.width > 96 ? "96px" : this.width);' src="{logo}" />
  <header class="sub-title col-xs-9 col-sm-11 col-md-11 col-lg-11">
    <h3>{head}</h3>
  </header>

</div>
<div>{hrefs}</div>

</section>
*/}

function url_template(){/*
<div class="col-xs-12 col-sm-6 col-md-4 col-lg-3">
<div class="list-group">
  <div class="list-group-item list-group-item-info skin{skin}" style="background-color:#a94442">
    <h4 class="list-group-item-heading" style="color:white;">
      {i}. {shortcut}
    </h4>
    <p class="list-group-item-text" style="color:white;">{name}</p>
    <p class="list-group-item-text text-warning" style="color:white;"><strong>{context}</strong></p>
    <p class="text-muted" style="color:white;">{des}</p>
  </div>
</div>

</div>
*/}

    // --------------------------------------------------

    var WIDTH = 1024;
    var STEP = 2;
    var HEIGHT = 1228;
    //var HEIGHT = (WIDTH-1);

    function _sq(x){
        //x = parseInt(x);
        return ((x)*(x)); // square
    } 
    function _cb(x){
        //x = parseInt(x);
        return abs((x)*(x)*(x)); // absolute value of cube
        
    } 
    function _cr(x){
        //x = parseInt(x);
        return (Math.pow((x),1.0/3.0)); // cube root
        
    } 
     
    // -----------------------------------------------------------------------------
     
    function RD(i, j){
        //i = parseInt(i);
        //j = parseInt(j);
        return (_sq(Math.cos(Math.atan2(j-512,i-512)/2))*255);
    }
     
    function GR(i, j){
        //i = parseInt(i);
        //j = parseInt(j);
        return (_sq(Math.cos(Math.atan2(j-512,i-512)/2-2*Math.acos(-1)/3))*255);
    }

    function BL(i, j){
        //i = parseInt(i);
        //j = parseInt(j);
        return (_sq(Math.cos(Math.atan2(j-512,i-512)/2+2*Math.acos(-1)/3))*255);
    }

    // -----------------------------------------------------------------------------

    function RD(i, j){
    var a=0,b=0,c,d,n=0;
    while((c=a*a)+(d=b*b)<4&&n++<880)
    {b=2*a*b+j*8e-9-.645411;a=c-d+i*8e-9+.356888;}
    return 255*Math.pow((n-80)/800,3.);
    }
     
    function GR(i, j){
    var a=0,b=0,c,d,n=0;
    while((c=a*a)+(d=b*b)<4&&n++<880)
    {b=2*a*b+j*8e-9-.645411;a=c-d+i*8e-9+.356888;}
    return 255*Math.pow((n-80)/800,.7);
    }
     
    function BL(i, j){
    var a=0,b=0,c,d,n=0;
    while((c=a*a)+(d=b*b)<4&&n++<880)
    {b=2*a*b+j*8e-9-.645411;a=c-d+i*8e-9+.356888;}
    return 255*Math.pow((n-80)/800,.5);
    }

    // -----------------------------------------------------------------------------
//var c ={};
//for(var i = 0;i<WIDTH;i++){
//  c[i]={};
//}
//function r(n){
//  return (rand()%n);
//}
//
//function RD(i, j){
//c[WIDTH][HEIGHT];return!c[i][j]?c[i][j]=!r(999)?r(256):RD((i+r(2))%1024,(j+r(2))%1024):c[i][j];
//}
// 
//function GR(i, j){
//c[WIDTH][HEIGHT];return!c[i][j]?c[i][j]=!r(999)?r(256):GR((i+r(2))%1024,(j+r(2))%1024):c[i][j];
//}
// 
//function BL(i, j){
//c[WIDTH][HEIGHT];return!c[i][j]?c[i][j]=!r(999)?r(256):BL((i+r(2))%1024,(j+r(2))%1024):c[i][j];
//}

    // -----------------------------------------------------------------------------


    function pixel_write(i, j){
        //var color[3];
        //color[0] = RD(i,j)&255;
        //color[1] = GR(i,j)&255;
        //color[2] = BL(i,j)&255;
        var color = 'rgb('+(RD(i,j)&255).toString()+','+(GR(i,j)&255).toString()+','+(BL(i,j)&255).toString()+')';
        gContext.beginPath();
        gContext.arc(i,j,STEP/2,0,Math.PI*2,true);
        gContext.closePath();
        gContext.fillStyle = color;//本来这里最初使用的是red，截图一看，傻眼了，怕上街被爱国者打啊，其实你懂的~~
        gContext.fill();


        //gContext.moveTo(i, j);
        //gContext.lineTo(i, j);
        //gContext.lineWidth = 1;
        //gContext.strokeStyle = '#'+RD(i,j)&255+GR(i,j)&255+BL(i,j)&255;
        //gContext.stroke();
    }


    function pic_main(){
        for(var j=0;j<WIDTH;j=j+STEP)
            for(var i=0;i<HEIGHT;i=i+STEP)
                pixel_write(i,j);

        //$("#result").hide();
        //document.getElementById("result").style.backgroundImage = 'url("' + gContext.canvas.toDataURL() + '")';
        return 0;
    }

    // --------------------------------------------------

  var gCanvas = null;
  var gContext = null;


  var gAppID=<?php echo getFromMap($_GET, 'appid', 0); ?>;
  gLang='<?php echo getFromMap($_GET, 'lang', 'cn'); ?>';
  $(function(){
    gCanvas = document.getElementById("canvas");
    gContext = gCanvas.getContext('2d');

    //WIDTH = $("#canvas").width();
    //HEIGHT = $("#canvas").height();

    if(!gAppID) gAppID = 2;
    //var u='query.php?op=all&appid='+gAppID+'&lang='+gLang;
    //$.ajax({url:u,
    //    dataType:"json",
    //    async:true,
    //    success : function(msg, textStatus) {
    //      get_all_callback(gAppID, msg);
    //      gen_page(gAppID, 0);
    //      $("#mykeys").show();
    //    }
    //},"text");


    pic_main();

    // --------------------------------------------------
  });//end of $(function(){
  </script>
</head>
<body>

<div id="wrapper">
<div id="container">

<div id="nav_data_src">
  <?php include 'navbars-inc.php' ?>
</div>


<div class="clearfix"></div>
</div><!-- end of search-container -->

<div class="clearfix"></div>

<div id="content" class="col-xs-12 col-sm-12 col-md-12 col-lg-12" name="top">

  <div id="result">
    载入中...
  </div>
  <canvas id="canvas" class="" width="1280" height="1024">您的浏览器不支持 canvas 标签</canvas>
  
  <div class="clearfix"></div>
  <div class="text-right" id="mykeys" style="display: none">
    <a href="./index.php" class="" >
      <img src="./css/log-orange.png" style='max-width:22px;_width:expression(this.width > 22 ? "22px" : this.width);'/>快捷键大全
    </a>
    <a href="./index.php" class="" >http://mykeys.sinaapp.com/</a>
    <span>
      <img src="./css/logo-black.png" style='max-width:22px;_width:expression(this.width > 22 ? "22px" : this.width);'/>
      关注微博(Ankiang)
    </span>
    <span>
      <img src="./css/logo.png" style='max-width:22px;_width:expression(this.width > 22 ? "22px" : this.width);'/>
      <a href="http://jq.qq.com/?_wv=1027&k=2COcMT9" target="_blank">加入快捷键交流QQ群(530154123)</a>
    </span>
  </div>
</div>


<div class="clearfix"></div>
<div id="hide-result"> </div>
<!-- .................................................... -->
</div><!-- end of container -->
</div><!-- end of wrapper -->
</body>
</html>
